package com.fr.report.painter;

import com.fr.base.FRFont;
import com.fr.base.Style;
import com.fr.base.core.ComparatorUtils;
import com.fr.base.core.GraphHelper;
import java.awt.Color;
import java.awt.FontMetrics;
import java.awt.Graphics2D;
import java.awt.geom.Point2D;
import java.io.Serializable;
import java.util.ArrayList;
import java.util.List;

class BiasLine
  implements Cloneable, Serializable
{
  private Point2D startPoint;
  private BiasLineSpan[] biasSpanInBiasLine;
  private String[] textInLine;
  private BiasLineElement[] lineElement;
  private static ArrayList stringInLine = new ArrayList();
  private String text;
  private Float[] textWidthInLine;
  private Integer[] textIndexes;
  private Style style;

  BiasLine(String paramString, Style paramStyle)
  {
    this.text = paramString;
    setStyle(paramStyle);
  }

  public void initial(BiasLineSpan[] paramArrayOfBiasLineSpan)
  {
    ArrayList localArrayList1 = new ArrayList();
    ArrayList localArrayList2 = new ArrayList();
    if (this.style == null)
      this.style = Style.DEFAULT_STYLE;
    FRFont localFRFont = getStyle().getFRFont();
    FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localFRFont);
    if ((paramArrayOfBiasLineSpan.length != 0) && (getStringInLine().size() < paramArrayOfBiasLineSpan.length))
    {
      BiasLineSpan localBiasLineSpan = paramArrayOfBiasLineSpan[getStringInLine().size()];
      double d1 = localBiasLineSpan.getLineWidth();
      int j = 0;
      int k = 0;
      double d2 = 0.0D;
      for (int l = 0; l < this.text.length(); ++l)
      {
        if (getStringInLine().size() >= paramArrayOfBiasLineSpan.length)
          break;
        if (this.text.charAt(l) == ' ')
        {
          k = l;
          if (d2 + localFontMetrics.charWidth(' ') <= d1)
          {
            d2 += localFontMetrics.charWidth(' ');
          }
          else
          {
            localArrayList1.add(new Integer(getStringInLine().size()));
            getStringInLine().add(this.text.substring(j, k));
            j = k;
            localArrayList2.add(new Float(d2));
            d2 = localFontMetrics.charWidth(' ');
            if (getStringInLine().size() < paramArrayOfBiasLineSpan.length)
              d1 = paramArrayOfBiasLineSpan[getStringInLine().size()].getLineWidth();
          }
        }
        else if (d2 + localFontMetrics.charWidth(this.text.charAt(l)) <= d1)
        {
          d2 += localFontMetrics.charWidth(this.text.charAt(l));
        }
        else
        {
          int i1 = 1;
          for (int i2 = j; i2 < k; ++i2)
            if (this.text.charAt(i2) != ' ')
            {
              i1 = 0;
              break;
            }
          if ((i1 != 0) || (getStringInLine().size() + 1 >= paramArrayOfBiasLineSpan.length))
          {
            k = l;
            localArrayList1.add(new Integer(getStringInLine().size()));
            getStringInLine().add(this.text.substring(j, k));
            j = k;
            localArrayList2.add(new Float(d2));
            d2 = localFontMetrics.charWidth(this.text.charAt(l));
            if (getStringInLine().size() < paramArrayOfBiasLineSpan.length)
              d1 = paramArrayOfBiasLineSpan[getStringInLine().size()].getLineWidth();
          }
          else
          {
            double d3 = localFontMetrics.stringWidth(this.text.substring(k + 1, l));
            double d4 = paramArrayOfBiasLineSpan[(getStringInLine().size() + 1)].getLineWidth();
            for (int i3 = l; i3 < this.text.length(); ++i3)
              if (this.text.charAt(i3) == ' ')
                break;
            if (localFontMetrics.stringWidth(this.text.substring(k + 1, i3)) < d4)
            {
              localArrayList1.add(new Integer(stringInLine.size()));
              getStringInLine().add(this.text.substring(j, k + 1));
              localArrayList2.add(new Float(localFontMetrics.stringWidth(this.text.substring(j, k + 1))));
              j = k + 1;
              d2 = localFontMetrics.stringWidth(this.text.substring(k + 1, l + 1));
              d1 = paramArrayOfBiasLineSpan[getStringInLine().size()].getLineWidth();
            }
            else
            {
              k = l;
              localArrayList1.add(new Integer(stringInLine.size()));
              getStringInLine().add(this.text.substring(j, k));
              j = k;
              localArrayList2.add(new Float(d2));
              d2 = localFontMetrics.charWidth(this.text.charAt(l));
              if (getStringInLine().size() < paramArrayOfBiasLineSpan.length)
                d1 = paramArrayOfBiasLineSpan[getStringInLine().size()].getLineWidth();
            }
          }
        }
      }
      if ((getStringInLine().size() < paramArrayOfBiasLineSpan.length) && (l >= this.text.length()) && (j < this.text.length()) && (localFontMetrics.charWidth(this.text.charAt(j)) <= d1))
      {
        localArrayList1.add(new Integer(stringInLine.size()));
        getStringInLine().add(this.text.substring(j, this.text.length()));
        localArrayList2.add(new Float(d2));
      }
    }
    this.textIndexes = new Integer[localArrayList1.size()];
    this.textWidthInLine = new Float[localArrayList2.size()];
    for (int i = 0; i < localArrayList1.size(); ++i)
      this.textIndexes[i] = new Integer(((Integer)localArrayList1.get(i)).intValue());
    for (i = 0; i < localArrayList2.size(); ++i)
      this.textWidthInLine[i] = new Float(((Float)localArrayList2.get(i)).floatValue());
    this.biasSpanInBiasLine = new BiasLineSpan[this.textIndexes.length];
    this.textInLine = new String[this.textIndexes.length];
    for (i = 0; i < this.textIndexes.length; ++i)
    {
      this.biasSpanInBiasLine[i] = paramArrayOfBiasLineSpan[this.textIndexes[i].intValue()];
      this.textInLine[i] = ((String)getStringInLine().get(this.textIndexes[i].intValue()));
    }
  }

  public void paintBiasLine(Graphics2D paramGraphics2D, boolean paramBoolean)
  {
    Graphics2D localGraphics2D = (Graphics2D)paramGraphics2D.create();
    if (this.style == null)
      this.style = Style.DEFAULT_STYLE;
    FRFont localFRFont = this.style.getFRFont();
    if (!(ComparatorUtils.equals(localFRFont, localGraphics2D.getFont())))
      localGraphics2D.setFont(localFRFont);
    Color localColor = localFRFont.getForeground();
    if (!(ComparatorUtils.equals(localColor, localGraphics2D.getPaint())))
      localGraphics2D.setPaint(localColor);
    localGraphics2D.setBackground(Color.black);
    FontMetrics localFontMetrics = GraphHelper.getFontMetrics(localFRFont);
    int i = localFontMetrics.getLeading();
    int j = localFontMetrics.getAscent();
    int k = localFontMetrics.getHeight();
    for (int l = 0; l < this.textInLine.length; ++l)
      if (paramBoolean)
        localGraphics2D.drawString(this.textInLine[l], ((float)this.biasSpanInBiasLine[l].getStartPoint().getX() + (float)this.biasSpanInBiasLine[l].getEndPoint().getX() - this.textWidthInLine[l].floatValue()) / 2.0F, (float)this.biasSpanInBiasLine[l].getStartPoint().getY() + j);
      else
        localGraphics2D.drawString(this.textInLine[l], (float)this.biasSpanInBiasLine[l].getStartPoint().getX(), (float)this.biasSpanInBiasLine[l].getStartPoint().getY() + j);
  }

  public BiasLineElement[] getLineElement()
  {
    return this.lineElement;
  }

  public void setLineElement(BiasLineElement[] paramArrayOfBiasLineElement)
  {
    this.lineElement = paramArrayOfBiasLineElement;
  }

  public String getText()
  {
    return this.text;
  }

  public void setText(String paramString)
  {
    this.text = paramString;
  }

  public static ArrayList getStringInLine()
  {
    return stringInLine;
  }

  public static void setStringInLine(ArrayList paramArrayList)
  {
    stringInLine = paramArrayList;
  }

  public Float[] getTextWidthInLine()
  {
    return this.textWidthInLine;
  }

  public void setTextWidthInLine(Float[] paramArrayOfFloat)
  {
    this.textWidthInLine = paramArrayOfFloat;
  }

  public Integer[] getTextIndexes()
  {
    return this.textIndexes;
  }

  public void setTextIndexes(Integer[] paramArrayOfInteger)
  {
    this.textIndexes = paramArrayOfInteger;
  }

  public Style getStyle()
  {
    return this.style;
  }

  public void setStyle(Style paramStyle)
  {
    this.style = paramStyle;
  }

  public Object clone()
    throws CloneNotSupportedException
  {
    return super.clone();
  }

  static
  {
    stringInLine.clear();
  }
}